<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('datax列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" name="templateId" th:value="${templateId}" id="templateId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>名称：</label>
                                <input type="text" name="na"/>
                            </li>
                            <li>
                                <label>数据库：</label>
                                <select name="idDb" th:with="type=${@baseDbService.selectAll()}">
                                    <option value=""></option>
                                    <option th:each="item : ${type}" th:text="${item.na}" th:value="${item.idDb}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('etl:datax:edit')}]];
        var removeFlag = [[${@permission.hasPermi('etl:datax:remove')}]];
        var prefix = ctx + "base/job/template/task";
        var dbData = [[${@baseDbService.selectAll()}]];
        function submitHandler() {
            var idTemplate = $("#templateId").val();
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            if(rows.length==0) {
                $.modal.alertError("需至少选择一条记录");
                return;
            }
            var data=[];
            $.each(rows,function (index,item) {
                data.push({"idFk":item.idDrawDatax,"idTemplate":idTemplate,"euType":"datax"});
            });
            $.ajax({
                url: prefix+"/addBatch",
                cache: false,
                async: false,
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(data),
                contentType: 'application/json;charset=UTF-8',
                success: function (result) {
                    if(result.code=="0") {
                        $.modal.close();
                    }
                }
            });
        }
        $(function() {
            var options = {
                url: prefix + "/datax/list",
                modalName: "datax",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'idDrawDatax',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'tbTar',
                    title: '编码'
                },
                {
                    field: 'na',
                    title: '名称'
                },
                {
                    field: 'idDb',
                    title: '数据源',
                    formatter: function(value, item, index) {
                        debugger;
                        let name='不存在';
                        $.each(dbData,function (i,t) {
                            if(value==t.idDb) {
                                name = t.na;
                                return false;
                            }
                        });
                        return name;
                    }
                },
                {
                    field: 'fgAct',
                    title: '启用标志',
                    formatter: function(value, item, index) {
                        if(value==1) {
                            return '启用'
                        }
                        return '停用';
                    }
                },
                {
                    field: 'euType',
                    title: '校验类型',
                    formatter: function(value, item, index) {
                        if(value==0) {
                            return '忽略'
                        } else if(value==1) {
                            return '月校验'
                        }
                        return '其他';
                    }
                },
                {
                    field: 'naEmpCre',
                    title: '创建人'
                },
                {
                    field: 'dtSysCre',
                    title: '创建时间'
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>